package com.wtj.user.controller;


import com.wtj.user.service.UserService;
import com.wtj.user.vo.UserPageReq;
import com.wtj.user.vo.UserPageResp;
import com.wtj.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 注：引入Mybatis-Plus 要在启动类上配置@MapperScan("com.wtj.user.mapper")
 *    引入Mybatis 要在配置类上配置xml文件的位置
 * mybatis-plus:
 *   mapper-locations: classpath:/com/wtj/user/mapper/*.xml
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     *  演示 mybatis-plus 的使用
     *  获取用户列表   curl http://localhost:8080/user/page?pageNum=1&pageSize=1
     * @param userPageReq
     * @return
     */
    @GetMapping("/page")
    public ResponseResult<List<UserPageResp>> getUserList(UserPageReq userPageReq) {
        List<UserPageResp> userPage = userService.getUserPage(userPageReq);
        return new ResponseResult<>(200,userPage);
    }

    /**
     *  演示 mybatis 的使用
     *  获取用户信息   curl http://localhost:8080/user/1
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<UserPageResp> getUserById(@PathVariable("id") Long id)  {
        UserPageResp user = userService.getUserById(id);
        return new ResponseResult<>(200,user);
    }
}
